﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using PowerCreator.LMS.Common.Script;
using PowerCreator.LMS.Web.Download;
using PowerCreator.LMS.Download.Entity;

public partial class sysadmin_DownManager_AddDownType : PowerCreator.LMS.Web.Base.WebBasePage
{
    DownType objType = new DownType();

    protected void Page_Load(object sender, EventArgs e)
    {
        //if (IsLicensed(PowerCreator.LMS.Action.Core.ActionInfo.AddJob))
        //{
        //    Script.RedirectURL(GetRefUrl());
        //}
        if (!IsPostBack)
        {
            InitPage();
            int DownTypeID = 0;
            if (Request.QueryString["DownTypeID"] != null)
            {
                DownTypeID = int.Parse(Request.QueryString["DownTypeID"].ToString());
                ViewState["DownTypeID"] = DownTypeID.ToString();
                BinderForm(DownTypeID);
            }
        }
    }
    protected override void InitPage()
    {
        //lbl_InfoTitle.Text = GetLanageValueByKey("lbl_AddJob_InfoTitle", PowerCreator.LMS.Language.LanagetItemType.Page);
        //lbl_JobName.Text = GetLanageValueByKey("lbl_AddJob_JobName", PowerCreator.LMS.Language.LanagetItemType.Page);
        //lbl_JobDescription.Text = GetLanageValueByKey("lbl_AddJob_JobDescription", PowerCreator.LMS.Language.LanagetItemType.Page);

        //btnSave.Text = GetLanageValueByKey("btn_Save", PowerCreator.LMS.Language.LanagetItemType.Page);
        //btnReset.Text = GetLanageValueByKey("btn_Reset", PowerCreator.LMS.Language.LanagetItemType.Page);
        //base.InitPage();

        lbl_InfoTitle_AddDownType.Text = GetLanageValueByKey("lab_AddDownType_InfoTitle", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_DownTypeName.Text = GetLanageValueByKey("lab_AddNewType_TypeName", PowerCreator.LMS.Language.LanagetItemType.Page);

        btnSave.Text = GetLanageValueByKey("btn_Save", PowerCreator.LMS.Language.LanagetItemType.Page);
        btnReset.Text = GetLanageValueByKey("btn_Reset", PowerCreator.LMS.Language.LanagetItemType.Page);
        base.InitPage();
    }
    private void BinderForm(int id)
    {
        VOTDownType vo = new VOTDownType();
        vo = objType.Load(id);
        txt_DownTypeName.Text = vo.DownTypeName;
    }
    private bool CheckPageData()
    {
        string search = string.Format("DownTypeName = '{0}'", txt_DownTypeName.Text);
        if (ViewState["DownTypeID"] != null)
        {
            search += "and DownTypeID<>" + ViewState["DownTypeID"].ToString();
        }
        if (objType.Count(search) != 0)
        {

            //lbl_msg_Error.Text = GetLanageValueByKey("lbl_msg_addjob_aspx_count", PowerCreator.LMS.Language.LanagetItemType.MSG);

            lbl_msg_Error.Text = "<br />" + GetLanageValueByKey("msg_AddNewType_checkMsg", PowerCreator.LMS.Language.LanagetItemType.Page);
            return false;
        }
        return true;
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (!CheckPageData()) return;
        VOTDownType vo = new VOTDownType();

        if (ViewState["DownTypeID"] == null)
        {
            vo.DownTypeName = txt_DownTypeName.Text.Trim();
            if (objType.AddDownType(vo))
            {
                string url = "ManagerDownType.aspx";
                Script.RedirectURL(url);
            }
        }
        else
        {
            vo = objType.Load(int.Parse(ViewState["DownTypeID"].ToString()));
            vo.DownTypeName = txt_DownTypeName.Text.Trim();
            if (objType.Update(vo))
            {
                string url = "ManagerDownType.aspx";
                Script.RedirectURL(url);
            }
        }
    }
    protected void btnReset_Click(object sender, EventArgs e)
    {
        string url = "ManagerDownType.aspx";
        Script.RedirectURL(url);
    }
}
